import { CommonUtil } from './../../../../common/utils/common.util';
import { CommentDetailService } from './service/comment-detail.service';
import { Component, OnInit } from '@angular/core';
import { Location } from '@angular/common'
import { Router, ActivatedRoute } from '@angular/router';


@Component({
    selector: 'app-estate-comment-detail',
    templateUrl: './estate-comment-detail.component.html',
    styleUrls: ['./estate-comment-detail.component.scss']
})
export class EstateCommentDetailComponent implements OnInit {

    public loading: boolean = true;
    public error: boolean = false;
    public isOne: boolean = true;
    public comments: any;
    public replys: any = [];
    public isType:boolean=false;
    tabs = ['楼盘', '户型'];

    constructor(
        private location: Location,
        private service: CommentDetailService,
        private routeInfo: ActivatedRoute,
        private commonUtil: CommonUtil,

    ) { }

    ngOnInit() {
        this.getDetails(this.routeInfo.snapshot.queryParams['comment']);
        this.isType = this.routeInfo.snapshot.queryParams['type'];
    }

    onClickLeft() {
        this.location.back()
    }

    onTabChange(e) {
        let index = e.index;
        if (index === 0) {
            this.isOne = true;
        } else {
            this.isOne = false;

        }

    }

    //api
    getDetails(id) {

        let req = {
            "comment": id
        };
        this.service.getDetails(req, res => {
            console.log(res);

            this.comments = res.Result;
            this.comments['NickPhoto'] = this.commonUtil.getThumbnail(res.Result.Nick.Photo);
            this.comments['Photo'] = this.commonUtil.getPhotoByName(res.Result.Photo,'Comment');

            if (this.comments.LayoutReference) {
                this.comments["LayoutPhoto"] = this.commonUtil.getPhotoByName(this.comments.LayoutReference.Photo,'户型图');
            }

            res.Result.Reply.forEach(element => {
                element['NickPhoto'] = this.commonUtil.getThumbnail(element.Nick.Photo);
            });
            this.replys = res.Result.Reply;

            this.loading = false;

        });
    }

}
